/**
 * Copyright:Copyright(c)2014-2017
 * Company:厦门市易致达物联网科技有限公司
 * @version 1.0
 */
package shop.controller.front.record;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import shop.core.FrontBaseController;
import shop.core.Services;
import shop.core.common.bean.JSONResult;
import shop.core.common.dao.page.PagerModel;
import shop.services.front.record.RecordService;
import shop.services.front.record.bean.Record;
import shop.services.front.wallet.WalletService;
import shop.services.front.wallet.bean.Wallet;
import shop.services.manage.system.bean.User;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**   
 * @类名称：RecordController
 * @创建人：Wzl
 * @创建时间：2017-10-13 下午16:13:14      
 * @版本号：1.0
 * @描述：用户交易记录
 */
@Controller
@RequestMapping("/front/record/")
public class RecordController extends FrontBaseController<Record> {
    private final  static  String RECORD_TRANSTYPE_CASH="1";

    @Resource
    private RecordService recordService;
    @Resource
    private WalletService walletService;
    @Override
    public Services<Record> getService() {
        return recordService;
    }


    /**
     * 跳转到交易记录页面（列表）
     *
     * @return
     */
    @RequestMapping("toRecordList")
    public String toRecordList() {return "/front/wallet/walletList";}

    /**
     * 跳转到提现申请页面
     *
     * @return
     */
    @RequestMapping("toWalletAdd")
    public String toWalletAdd() {return "/front/wallet/Addwallet";}

    /**
     * 查询收益记录
     *
     * @return
     * @throws Exception
     */
    @RequestMapping("selectRecordList")
    @ResponseBody
    public JSONResult selectRecordList(HttpSession session, Record record){
        User user = (User) session.getAttribute("userInfo");
        record.setUserID(user.getId());
        List<Record> rsList = recordService.selectList(record);
        for(Record recordInfo :rsList){
            if(RECORD_TRANSTYPE_CASH.equals(recordInfo.getTransType())){
                recordInfo.setBuyerName(user.getNickname());
                Wallet wallet=new Wallet();
                wallet.setId(recordInfo.getTransID());
                wallet=walletService.selectOne(wallet);
                recordInfo.setWalletType(wallet.getType());
                recordInfo.setWalletStatus(wallet.getStatus());
            }
        }
        JSONResult jsonResult = new JSONResult();
        jsonResult.setData(rsList);
        return jsonResult;
    }

    @Override
    public JSONResult deleteJson(HttpServletRequest request, Record record) throws Exception {
        return null;
    }
}
